﻿<!DOCTYPE HTML>
<html>
<head>
	<meta charset="utf-8">
	<meta name="renderer" content="webkit|ie-comp|ie-stand">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
	<meta http-equiv="Cache-Control" content="no-siteapp" />
	<!--[if lt IE 9]>
	<script type="text/javascript" src="lib/html5shiv.js"></script>
	<script type="text/javascript" src="lib/respond.min.js"></script>
	<![endif]-->
	<link rel="stylesheet" type="text/css" href="static/h-ui/css/H-ui.min.css" />
	<link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/H-ui.admin.css" />
	<link rel="stylesheet" type="text/css" href="lib/Hui-iconfont/1.0.8/iconfont.css" />
	<link rel="stylesheet" type="text/css" href="static/h-ui.admin/skin/default/skin.css" id="skin" />
	<link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/style.css" />
	<!--[if IE 6]>
	<script type="text/javascript" src="lib/DD_belatedPNG_0.0.8a-min.js" ></script>
	<script>DD_belatedPNG.fix('*');</script>
	<![endif]-->
	<title>环境管理</title>
	<script type="text/javascript" src="lib/loading.js"></script>
</head>
<body>

<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 环境管理 <span class="c-gray en">&gt;</span> 环境列表 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.reload();" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
<div class="page-container">
	<div class="cl pd-5 bg-1 bk-gray">
		<span class="l">
			<a href="javascript:;" onclick="datadel()" class="btn btn-danger radius"><i class="Hui-iconfont">&#xe6e2;</i> 批量删除</a>
			<a class="btn btn-primary radius" href="javascript:;" onclick="tenv_add('添加环境','tenv-add.html','800','300')"><i class="Hui-iconfont">&#xe600;</i> 添加环境</a>
		</span>
		<span class="r">共有数据：<strong id="total"></strong> 条</span>
	</div>
	<table class="table table-border table-bordered table-hover table-bg">
		<thead>
		<tr>
			<th scope="col" colspan="6">环境管理</th>
		</tr>
		<tr class="text-c">
			<th width="25"><input type="checkbox" value="" name=""></th>
			<th width="40">id</th>
			<th width="200">环境标识</th>
			<th>环境描述</th>
			<th width="70">操作</th>
		</tr>
		</thead>
        <!--结果区-->
		<tbody id="table">
		</tbody>
	</table>
</div>

<script type="text/javascript" src="lib/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="static/h-ui/js/H-ui.min.js"></script>
<script type="text/javascript" src="static/h-ui.admin/js/H-ui.admin.js"></script>
<script type="text/javascript" src="lib/datatables/1.10.0/jquery.dataTables.min.js"></script>
<script type="text/javascript">
	//loading
    $(function () {
        $.ajaxSetup({
            layerIndex:-1,
            beforeSend: function () { //插件加载前
                this.layerIndex = layer.load(1, { shade: [0.01, '#fff'] });
                //$('#submit').val("正在加载请稍等...")
            },
            complete: function () { //完成加载后执行
                layer.close(this.layerIndex); //完成加载后关闭loading
            },
            error: function () { //报错时执行
                layer.alert('显示异常，请刷新后重试', {
                    icon: 0,
                    skin: 'layer-ext-moon'
                });
            }
        });
    });

    //查询环境列表
	$(document).ready(function () {
        $.ajax({
            type: "post",
            url: "/tenv/selectAll",
            data: {
            },
            dataType: "json",
            success: function (data) {
                //alert( JSON.stringify(data).);
				var status=data.status;
				var msg=data.msg;
				var list=data.data;
                var total=list.length;
				console.log(data);
                var html = "";

                if(status == 0){
                    for(var i=0;i<list.length;i++){
                        var row = list[i];
                        var rowHtml = "<tr class=\"text-c\">\n" +
                            "<td><input type=\"checkbox\" value=\"\" name=\"\"></td>\n" +
                            "<td>"+row.id+"</td>\n" +
                            "<td>"+row.envkey+"</td>\n" +
                            "<td>"+row.remark+"</td>\n" +
                            "<td class=\"f-14\"><a title=\"编辑\" href=\"javascript:;\" onclick=\"tenv_edit('环境编辑','tenv-edit.html',"+row.id+",'800','300')\" style=\"text-decoration:none\"><i class=\"Hui-iconfont\">&#xe6df;</i></a> \n" +
                            "<a title=\"删除\"hidden=\"hidden\"href=\"javascript:;\" onclick=\"tenv_del(this,"+row.id+")\" class=\"ml-5\" style=\"text-decoration:none\"><i class=\"Hui-iconfont\">&#xe6e2;</i></a></td>\n" +
                            "</tr>";
                        html = html + rowHtml;
                    }
                    $("#total").append(total);
                    $("#table").append(html);
                    //分页
                    $('.table').dataTable({
                        "aaSorting": [[ 1, "desc" ]],//默认第几个排序
                        "bLengthChange": true, //改变每页显示数据数量
                        "bFilter": false, //过滤功能
                        "bStateSave": true,//状态保存
                        "aoColumnDefs": [
                            //{"bVisible": false, "aTargets": [ 3 ]} //控制列的隐藏显示
                            {"orderable":false,"aTargets":[0,4]}// 制定列不参与排序
                        ]
                    });

				}else{
                    layer.alert(msg, {
                        icon: 0,
                        skin: 'layer-ext-moon'
                    })
				}
                $("tr:odd").css("background-color","AliceBlue");
            }
        });

    });

    /*环境-添加*/
    function tenv_add(title,url,w,h){
        layer_show(title,url,w,h);
    }
    /*环境-编辑*/
    function tenv_edit(title,url,id,w,h){
        url= url + "?id="+id;
        layer_show(title,url,w,h);

    }
    /*环境-删除*/
    function tenv_del(obj,id){
        layer.confirm('环境删除将会连带删除此环境下的测试用例,确认要删除环境吗?',function(index){
            //alert("要删除的id="+id);
            $.ajax({
                type: 'POST',
                url: '/tenv/deleteOne',
                data:{
                    id:id
                },
                dataType: 'json',
                success: function(data){
                    var status=data.status;
                    var msg=data.msg;
                    if(status == 0){
                        $(obj).parents("tr").remove();
                        window.location.reload();
                        layer.msg('已删除!',{icon:1,time:1000});
                    }else{
                        layer.alert(msg, {
                            icon: 0,
                            skin: 'layer-ext-moon'
                        })
                    }

                },
                error:function(data) {
                    console.log(data);
                },
            });
        });
    }
</script>
</body>
</html>